package com.jinxin.platform.cdperprotypay.controller;

import com.jinxin.platform.cdperprotypay.pojo.vo.PayNoticVO;
import com.jinxin.platform.cdperprotypay.service.ChargeDetailService;
import com.jinxin.platform.cdperprotypay.support.IPUtils;
import com.jinxin.platform.cdperprotypay.support.NetworkUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author : zhangpeng
 * @date : 2021-02-04 09:35:29
 **/
@Slf4j
@RestController
@RequestMapping("/unAuth/cdperprotypay")
public class PayApi {

    @Autowired
    private ChargeDetailService chargeDetailService;

    @PostMapping("/payResNotic")
    public String payResNotic(HttpServletRequest request, PayNoticVO noticVO){
        String reqIp = IPUtils.getIp(request);
        String localIp = "";
        try {
            localIp = NetworkUtils.getLocalIP();
        } catch (Exception e) {
            log.error("payResNotic: " ,e );
            return "fail";
        }
        if(!reqIp.equals(localIp) ){
            log.info("非本机回调 reqIP:"+ reqIp +"; localIp:"+ localIp );
            return "fail";
        }

        return chargeDetailService.resWxOrder(noticVO);
    }

}
